package com.jy.api.service.impl;

import com.jy.api.dao.StoreConfigDao;
import com.jy.api.domain.StoreConfig;
import com.jy.api.service.StoreConfigService;
import com.jy.api.signUpReq.admin.StoresConfigSignUpReq;
import com.jy.api.util.UuidUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

/**
 * Created by lihu on 2018/1/19.
 */
@Service
public class StoreConfigServiceImpl implements StoreConfigService {

    @Autowired
    StoreConfigDao storeConfigDao;

    @Override
    @Transactional
    public void updateStoreConfig(StoresConfigSignUpReq signUpReq) {
        StoreConfig storeConfig = storeConfigDao.findByStoreId(signUpReq.getStoreId());
        if (storeConfig == null) {
            storeConfig = new StoreConfig(UuidUtil.getUuid(), signUpReq.getStoreId());
        }
        storeConfig.setGiveCouponId(signUpReq.getGiveCouponId());
        storeConfigDao.save(storeConfig);
    }
}
